<template>
	<view class="">
		<u--form :model="form" ref="uForm" :rules="rules">
			<u-form-item label="回访客户" prop="username" borderBottom @click="show = true" ref="item1"
				:customStyle="btnStyle1">
				<u--input v-model="form.name" disabled disabledColor="#ffffff" placeholder="请选择"
					suffixIcon="arrow-down"></u--input>
			</u-form-item>
			<u-form-item label="回访内容" prop="username" borderBottom ref="item1" :customStyle="btnStyle1">
				<u--textarea v-model="form.value1" placeholder="请输入内容" count></u--textarea>
			</u-form-item>
			<u-picker :show="show" :columns="businesslist" keyName="nickname" @cancel="show = false"
				@confirm="confirm"></u-picker>
			<u-button @click="submit" color="#19BC9C" :customStyle="btnStyle">添加</u-button>
			<!-- 消息提示 -->
			<u-toast ref="uToast"></u-toast>
		</u--form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				id: 0,
				form: {
					name: "",
					id: "",
					value1: "",
				},
				btnStyle1: {
					marginLeft: "50px",
					width: '80%',
					label: "30px"
				},
				businesslist: [],
				LoginUser: {},

				btnStyle: {
					position: 'fixed',
					bottom: '0px',
					width: '100%',
					bottom: '0px'
				},
				rules: {
					'value1': {
						min: 3,
						required: true,
						message: '不低于3个字',
						trigger: ['change']
					},

				},
			}
		},
		onLoad(options) {

			this.LoginUser = uni.getStorageSync('LoginUser') ? uni.getStorageSync('LoginUser') : {};
			this.id = options.id ?? 0
			this.getBuisnessData()
			this.getVisitData()

		},
		onShow() {
			this.$u.auth.check()

		},
		methods: {
			confirm({
				value
			}) {
				this.show = false
				this.form.name = value[0].nickname
				this.form.id = value[0].id
			},
			async getBuisnessData() {

				let result = await this.$u.api.business.buslist({
					adminid: this.LoginUser.id,
				})
				if (result.code == 1) {
					this.businesslist.push(result.data)
					// console.log(this.businesslist)
				}
			},
			async getVisitData() {
				let result = await this.$u.api.business.getVisitData({
					id: this.id
				})

				if (result.code == 1) {

					this.form.name = result.data.business.nickname
					this.form.value1 = result.data.content
					this.form.id = result.data.business.id
				}
			},
			submit() {
				this.$refs.uForm.validate().then(async (res) => {

					let result = await this.$u.api.business.RevisitEdit({
						id: this.id,
						content: this.form.value1,
						busid: this.form.id,
					})
					if (result.code == 1) {
						this.$refs.uToast.show({
							type: 'success',
							message: result.msg,
							complete: () => {
								uni.navigateTo({
									url: '/pages/business/revisit/index'
								})
							}
						})
					}
				}).catch(errors => {})
			}
		}
	}
</script>

<style>
</style>